﻿//-------------------------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2011 , Hairihan TECH, Ltd.
//-------------------------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;

namespace DotNet.BaseManager
{
    using DotNet.DbUtilities;
    using DotNet.Utilities;

    /// <summary>
    ///	BaseManager
    /// 通用基类部分
    ///
    /// 总觉得自己写的程序不上档次，这些新技术也玩玩，也许做出来的东西更专业了。
    /// 修改纪录
    ///
    ///		2010.06.23 版本：1.4 JiRiGaLa 删除简化了一些重复的函数功能。
    ///		2007.11.22 版本：1.3 JiRiGaLa 创建没有BaseSystemInfo的构造函数。
    ///		2007.11.20 版本：1.2 JiRiGaLa 完善有数据库连接、当前操作员信息的构造函数、增加NonSerialized。
    ///		2007.11.15 版本：1.1 JiRiGaLa 设置 SetParameter 函数功能。
    ///		2007.08.01 版本：1.0 JiRiGaLa 提炼了最基础的方法部分、觉得这些是很有必要的方法。
    ///
    /// 版本：1.4
    ///
    /// <author>
    ///		<name>JiRiGaLa</name>
    ///		<date>2010.06.23</date>
    /// </author>
    /// </summary>
    public abstract class BaseManager : IBaseManager
    {
        /// <summary>
        /// 数据表主键，需要用单一字段做为主键，建议默认为Id字段
        /// </summary>
        public string PrimaryKey = "Id";

        /// <summary>
        /// 是否自增量？大并发数据主键生成需要用这个方法
        /// 不是所有的情况下，都是在进行插入操作的，也不都是有Id字段的
        /// </summary>
        public bool Identity = true;

        /// <summary>
        /// 插入数据时，是否需要返回主键
        /// 默认都是需要插入操作时都要返回主键的
        /// </summary>
        public bool ReturnId = true;

        /// <summary>
        /// 当前控制的表名
        /// </summary>
        public string CurrentTableName = string.Empty;

        private static object locker = new Object();

        private IDbHelper dbHelper = null;

        /// <summary>
        /// 当前的数据库连接
        /// </summary>
        public IDbHelper DbHelper
        {
            set
            {
                dbHelper = value;
            }
            get
            {
                if (dbHelper == null)
                {
                    lock (locker)
                    {
                        if (dbHelper == null)
                        {
                            dbHelper = DbHelperFactory.GetHelper();

                            // 是自动打开关闭数据库状态
                            dbHelper.AutoOpenClose = true;
                        }
                    }
                }
                return dbHelper;
            }
        }

        protected BaseUserInfo UserInfo = null;

        public BaseManager()
        {
        }

        public BaseManager(IDbHelper dbHelper)
            : this()
        {
            DbHelper = dbHelper;
        }

        public BaseManager(IDbHelper dbHelper, BaseUserInfo userInfo)
            : this(dbHelper)
        {
            UserInfo = userInfo;
        }

        /// <summary>
        /// 设置数据库连接
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        public void SetConnection(IDbHelper dbHelper)
        {
            DbHelper = dbHelper;
        }

        /// <summary>
        /// 设置当前操作员
        /// </summary>
        /// <param name="userInfo">当前操作员</param>
        public void SetConnection(BaseUserInfo userInfo)
        {
            UserInfo = userInfo;
        }

        /// <summary>
        /// 设置数据库连接、当前操作员
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">当前操作员</param>
        public void SetConnection(IDbHelper dbHelper, BaseUserInfo userInfo)
        {
            this.SetConnection(dbHelper);
            UserInfo = userInfo;
        }

        public virtual void SetParameter(IDbHelper dbHelper)
        {
            DbHelper = dbHelper;
        }

        public virtual void SetParameter(BaseUserInfo userInfo)
        {
            UserInfo = userInfo;
        }

        public virtual void SetParameter(IDbHelper dbHelper, BaseUserInfo userInfo)
        {
            DbHelper = dbHelper;
            UserInfo = userInfo;
        }

        //
        // 类对应的数据库最终操作
        //
        public virtual string AddEntity(object entity)
        {
            return string.Empty;
        }

        public virtual int UpdateEntity(object entity)
        {
            return 0;
        }

        public virtual int DeleteEntity(object id)
        {
            return DeleteEntity(BaseBusinessLogic.FieldId, id);
        }

        public virtual int DeleteEntity(string name, object value)
        {
            return DbLogic.Delete(DbHelper, this.CurrentTableName, name, value);
        }

        //
        // 对象事件触发器（编写程序的人员，可以不实现这些方法）
        //
        public virtual bool AddBefore()
        {
            // 这个函数需要覆盖
            return true;
        }

        public virtual bool AddAfter()
        {
            // 这个函数需要覆盖
            return true;
        }

        public virtual bool UpdateBefore()
        {
            // 这个函数需要覆盖
            return true;
        }

        public virtual bool UpdateAfter()
        {
            // 这个函数需要覆盖
            return true;
        }

        public virtual bool GetBefore(string id)
        {
            // 这个函数需要覆盖
            return true;
        }

        public virtual bool GetAfter(string id)
        {
            // 这个函数需要覆盖
            return true;
        }

        public virtual bool DeleteBefore(string id)
        {
            // 这个函数需要覆盖
            return true;
        }

        public virtual bool DeleteAfter(string id)
        {
            // 这个函数需要覆盖
            return true;
        }

        //
        // 批量操作保存
        //
        public virtual int BatchSave(DataTable dataTable)
        {
            return 0;
        }

        //
        // 读取一条记录
        //
        public virtual DataTable Get(string id)
        {
            return this.GetDT(BaseBusinessLogic.FieldId, id);
        }

        public virtual DataTable Get(string name, object value)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name, value);
        }

        public virtual DataTable Get(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual object GetFrom(DataTable dataTable)
        {
            return GetFrom(dataTable, string.Empty);
        }

        public virtual object GetFrom(DataTable dataTable, string id)
        {
            return GetFrom(dataTable, BaseBusinessLogic.FieldId, id);
        }

        public virtual object GetFrom(DataTable dataTable, string name, object value)
        {
            // 清除属性
            foreach (DataRow dataRow in dataTable.Rows)
            {
                if ((value == null) || (value.ToString().Length == 0) || (dataRow[name].ToString().Equals(value)))
                {
                    GetFrom(dataRow);
                    break;
                }
            }
            return this;
        }

        public virtual object Get(DataTable dataTable, string id)
        {
            return GetFrom(dataTable, BaseBusinessLogic.FieldId, id);
        }

        public virtual object Get(DataTable dataTable, string name, object value)
        {
            return GetFrom(dataTable, name, value);
        }

        public virtual object GetFrom(DataRow dataRow)
        {
            return this;
        }

        //
        // 获得主键列表
        //

        public virtual string[] GetIds()
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName);
        }

        public virtual string[] GetIds(string targetField)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, targetField);
        }

        public virtual string[] GetIds(string targetField, int topLimit)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, targetField, topLimit);
        }

        public virtual string[] GetIds(string name, object value)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name, value);
        }

        public virtual string[] GetIds(string name, object value, string targetField)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name, value, targetField);
        }

        public virtual string[] GetIds(string name, object value, string targetField, int topLimit)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name, value, targetField, topLimit);
        }

        public virtual string[] GetIds(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual string[] GetIds(string name1, object value1, string name2, object value2, string targetField)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField);
        }

        public virtual string[] GetIds(string name1, object value1, string name2, object value2, string targetField, int topLimit)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField, topLimit);
        }

        public virtual string[] GetIds(string name, Object[] values)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name, values);
        }

        public virtual string[] GetIds(string name, Object[] values, string targetField)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, name, values, targetField);
        }

        public virtual string[] GetIds(string[] names, Object[] values)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, names, values);
        }

        public virtual string[] GetIds(string[] names, Object[] values, string targetField)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, names, values, targetField);
        }

        public virtual string[] GetIds(string[] names, Object[] values, string targetField, int topLimit)
        {
            return DbLogic.GetIds(DbHelper, this.CurrentTableName, names, values, targetField, topLimit);
        }

        //
        // 读取多条记录
        //
        public virtual DataTable GetDT()
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName);
        }

        public virtual DataTable GetDT(string name, Object[] values)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name, values);
        }

        public virtual DataTable GetDT(string order)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, order);
        }

        public virtual DataTable GetDT(string[] ids)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, ids);
        }

        public virtual DataTable GetDT(string name, object value)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name, value);
        }

        public virtual DataTable GetDT(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual DataTable GetDT(string name1, object value1, string name2, object value2, string order)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name1, value1, name2, value2, order);
        }

        public virtual DataTable GetDT(string name1, object value1, string name2, object value2, string order, int topLimit)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name1, value1, name2, value2, order, topLimit);
        }

        public virtual DataTable GetDT(string name, object value, string order)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name, value, order);
        }

        public virtual DataTable GetDT(string name, Object[] values, string order)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name, values, order);
        }

        public virtual DataTable GetDT(string order, int topLimit)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, order, topLimit);
        }

        public virtual DataTable GetDT(string name, object value, string order, int topLimit)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, name, value, order, topLimit);
        }

        public virtual DataTable GetDT(string[] names, Object[] values)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, names, values);
        }

        public virtual DataTable GetDT(string[] names, Object[] values, string order)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, names, values, order);
        }

        public virtual DataTable GetDT(string[] names, Object[] values, string order, int topLimit)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, names, values, order, topLimit);
        }

        //
        // 读取属性
        //
        public virtual string GetProperty(object id, string targetField)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, id, targetField);
        }

        public virtual string GetProperty(string name, object value, string targetField)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, name, value, targetField);
        }

        public virtual string GetProperty(string name1, object value1, string name2, object value2, string targetField)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField);
        }

        public virtual string GetProperty(string[] names, object[] values, string targetField)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, names, values, targetField);
        }

        public virtual string GetId(string name, object value)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, name, value, BaseBusinessLogic.FieldId);
        }

        public virtual string GetId(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, name1, value1, name2, value2, BaseBusinessLogic.FieldId);
        }

        public virtual string GetId(string[] names, object[] values)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, names, values, BaseBusinessLogic.FieldId);
        }

        //
        // 设置属性
        //
        public virtual int SetProperty(string targetField, object targetValue)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, targetField, targetValue);
        }

        public virtual int SetProperty(object id, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, id, targetField, targetValue);
        }

        public virtual int SetProperty(object id, string[] targetFields, Object[] targetValues)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, id, targetFields, targetValues);
        }

        public virtual int SetProperty(string name, object value, string[] targetFields, Object[] targetValues)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, name, value, targetFields, targetValues);
        }

        public virtual int SetProperty(string name, string[] values, string[] targetFields, Object[] targetValues)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, name, values, targetFields, targetValues);
        }

        public virtual int SetProperty(object[] ids, string[] targetFields, Object[] targetValues)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, ids, targetFields, targetValues);
        }

        public virtual int SetProperty(string name, object value, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, name, value, targetField, targetValue);
        }

        public virtual int SetProperty(string name1, object value1, string name2, object value2, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField, targetValue);
        }

        public virtual int SetProperty(string name, Object[] values, string targetField, object targetValue)
        {
            int returnValue = 0;
            if (values == null)
            {
                returnValue += DbLogic.SetProperty(DbHelper, this.CurrentTableName, name, string.Empty, targetField, targetValue);
            }
            else
            {
                for (int i = 0; i < values.Length; i++)
                {
                    returnValue += DbLogic.SetProperty(DbHelper, this.CurrentTableName, name, values[i], targetField, targetValue);
                }
            }
            return returnValue;
        }

        public virtual int SetProperty(object[] ids, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, ids, targetField, targetValue);
        }

        public virtual int SetProperty(string[] names, object[] values, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(DbHelper, this.CurrentTableName, names, values, targetField, targetValue);
        }

        #region public virtual int SetDeleted(object id) 删除标志

        /// <summary>
        /// 删除标志
        /// </summary>
        /// <param name="userInfo">当前操作员</param>
        /// <param name="id">便笺ID</param>
        /// <returns>影响行数</returns>
        public virtual int SetDeleted(object id)
        {
            return this.SetProperty(BaseBusinessLogic.FieldId, id, BaseBusinessLogic.FieldDeletionStateCode, "1");
        }

        #endregion public virtual int SetDeleted(object id) 删除标志

        #region public virtual int SetDeleted(object[] ids) 批量删除标志

        /// <summary>
        /// 批量删除标志
        /// </summary>
        /// <param name="ids">便笺主键数组</param>
        /// <returns>影响行数</returns>
        public virtual int SetDeleted(object[] ids)
        {
            return this.SetProperty(BaseBusinessLogic.FieldId, ids, BaseBusinessLogic.FieldDeletionStateCode, "1");
        }

        #endregion public virtual int SetDeleted(object[] ids) 批量删除标志

        #region public virtual int SetDeleted(string[] names, object[] values) 批量删除标志

        /// <summary>
        /// 批量删除标志
        /// </summary>
        /// <param name="ids">便笺主键数组</param>
        /// <returns>影响行数</returns>
        public virtual int SetDeleted(string[] names, object[] values)
        {
            return this.SetProperty(names, values, BaseBusinessLogic.FieldDeletionStateCode, "1");
        }

        #endregion public virtual int SetDeleted(string[] names, object[] values) 批量删除标志

        #region public virtual int SetDeletedAll() 删除标志当前操作员的全部便笺

        /// <summary>
        /// 删除标志当前操作员的全部便笺
        /// </summary>
        /// <returns>影响行数</returns>
        public virtual int SetDeletedAll()
        {
            return this.SetProperty(BaseBusinessLogic.FieldCreateUserId, UserInfo.Id, BaseBusinessLogic.FieldDeletionStateCode, "1");
        }

        #endregion public virtual int SetDeletedAll() 删除标志当前操作员的全部便笺

        #region public virtual int ChangeEnabled(object id) 更新一条记录状态

        /// <summary>
        /// 变更便笺状态
        /// </summary>
        /// <param name="id">便笺ID</param>
        /// <returns>影响行数</returns>
        public virtual int ChangeEnabled(object id)
        {
            int returnValue = 0;
            string sqlQuery = " UPDATE " + this.CurrentTableName
                            + " SET " + BaseBusinessLogic.FieldEnabled + " = (CASE " + BaseBusinessLogic.FieldEnabled + " WHEN 0 THEN 1 WHEN 1 THEN 0 END) "
                            + " WHERE (" + BaseBusinessLogic.FieldId + " = " + DbHelper.GetParameter(BaseBusinessLogic.FieldId) + ")";
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = BaseBusinessLogic.FieldId;
            values[0] = id;
            returnValue = DbHelper.ExecuteNonQuery(sqlQuery, DbHelper.MakeParameters(names, values));
            return returnValue;
        }

        #endregion public virtual int ChangeEnabled(object id) 更新一条记录状态

        //
        // 判断数据是否存在
        //
        public virtual bool Exists(object id)
        {
            return DbLogic.Exists(DbHelper, this.CurrentTableName, this.PrimaryKey, id);
        }

        public virtual bool Exists(object[] ids)
        {
            return DbLogic.Exists(DbHelper, this.CurrentTableName, this.PrimaryKey, ids);
        }

        public virtual bool Exists(string name, object value)
        {
            return DbLogic.Exists(DbHelper, this.CurrentTableName, name, value);
        }

        public virtual bool Exists(string name, object value, object id)
        {
            string[] names = new string[] { name };
            Object[] values = new object[] { value };
            return DbLogic.Exists(DbHelper, this.CurrentTableName, names, values, this.PrimaryKey, id);
        }

        public virtual bool Exists(string name1, object value1, string name2, object value2)
        {
            return DbLogic.Exists(DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual bool Exists(string name1, object value1, string name2, object value2, object id)
        {
            return DbLogic.Exists(DbHelper, this.CurrentTableName, name1, value1, name2, value2, this.PrimaryKey, id);
        }

        public virtual bool Exists(string[] names, object[] values)
        {
            return DbLogic.Exists(DbHelper, this.CurrentTableName, names, values);
        }

        public virtual bool Exists(string[] names, object[] values, object id)
        {
            return DbLogic.Exists(DbHelper, this.CurrentTableName, names, values, this.PrimaryKey, id);
        }

        //
        // 删除数据部分
        // force 是否强制删除关联数据
        //
        public virtual int Delete()
        {
            return DbLogic.Delete(DbHelper, this.CurrentTableName);
        }

        public virtual int Delete(object id)
        {
            return DeleteEntity(id);
        }

        public virtual int Delete(object id, bool force)
        {
            // 这个函数需要覆盖
            return DbLogic.Delete(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, id);
        }

        public virtual int Delete(string name, object value)
        {
            return DbLogic.Delete(DbHelper, this.CurrentTableName, name, value);
        }

        public virtual int Delete(string name, object value, bool force)
        {
            // 这个函数需要覆盖
            return DbLogic.Delete(DbHelper, this.CurrentTableName, name, value);
        }

        public virtual int Delete(string name1, object value1, string name2, object value2)
        {
            return DbLogic.Delete(DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual int Delete(string name1, object value1, string name2, object value2, bool force)
        {
            // 这个函数需要覆盖
            return DbLogic.Delete(DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual int BatchDelete(object[] ids)
        {
            return DbLogic.BatchDelete(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, ids);
        }

        public virtual int BatchDelete(object[] ids, bool force)
        {
            // 这个函数需要覆盖
            return DbLogic.BatchDelete(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, ids);
        }

        public virtual int BatchDelete(string name, object[] values)
        {
            return DbLogic.BatchDelete(DbHelper, this.CurrentTableName, name, values);
        }

        public virtual int BatchDelete(string[] names, object[] values)
        {
            return DbLogic.BatchDelete(DbHelper, this.CurrentTableName, names, values);
        }

        public virtual int BatchDelete(string[] names, object[] values, bool force)
        {
            // 这个函数需要覆盖
            return DbLogic.BatchDelete(DbHelper, this.CurrentTableName, names, values);
        }

        public virtual int Truncate()
        {
            return DbLogic.Truncate(DbHelper, this.CurrentTableName);
        }

        /// 直接执行一些SQL语句的方法

        #region public int ExecuteNonQuery(string commandText)

        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(string commandText)
        {
            return DbHelper.ExecuteNonQuery(commandText);
        }

        #endregion public int ExecuteNonQuery(string commandText)

        #region public int ExecuteNonQuery(string commandText, DbParameter[] dbParameters) 执行查询语句

        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(string commandText, DbParameter[] dbParameters)
        {
            return DbHelper.ExecuteNonQuery(commandText, dbParameters);
        }

        #endregion public int ExecuteNonQuery(string commandText, DbParameter[] dbParameters) 执行查询语句

        #region public object ExecuteScalar(string commandText) 执行查询语句

        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <returns>object</returns>
        public object ExecuteScalar(string commandText)
        {
            return DbHelper.ExecuteScalar(commandText);
        }

        #endregion public object ExecuteScalar(string commandText) 执行查询语句

        #region public object ExecuteScalar(string commandText, DbParameter[] dbParameters) 执行查询语句

        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>Object</returns>
        public object ExecuteScalar(string commandText, DbParameter[] dbParameters)
        {
            return DbHelper.ExecuteScalar(commandText, dbParameters);
        }

        #endregion public object ExecuteScalar(string commandText, DbParameter[] dbParameters) 执行查询语句

        #region public DataTable Fill(string commandText) 填充数据表

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandText">查询</param>
        /// <returns>数据表</returns>
        public DataTable Fill(string commandText)
        {
            return DbHelper.Fill(commandText);
        }

        #endregion public DataTable Fill(string commandText) 填充数据表

        #region public DataTable Fill(string commandText, DbParameter[] dbParameters) 填充数据表

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(string commandText, DbParameter[] dbParameters)
        {
            return DbHelper.Fill(commandText, dbParameters);
        }

        #endregion public DataTable Fill(string commandText, DbParameter[] dbParameters) 填充数据表

        ///
        /// 重新生成排序码
        ///

        #region public int BatchSetSortCode(string parentId) 重置排序码

        /// <summary>
        /// 重置排序码
        /// </summary>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int BatchSetSortCode(string[] ids)
        {
            int returnValue = 0;
            BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper);
            string[] sortCodes = sequenceManager.GetBatchSequence(this.CurrentTableName, ids.Length);
            for (int i = 0; i < ids.Length; i++)
            {
                returnValue += this.SetProperty(ids[i], BaseBusinessLogic.FieldSortCode, sortCodes[i]);
            }
            return returnValue;
        }

        #endregion public int BatchSetSortCode(string parentId) 重置排序码

        #region public int BatchSetCode(string[] ids, string[] codes) 重置编号

        /// <summary>
        /// 重置编号
        /// </summary>
        /// <param name="ids">主键数组</param>
        /// <param name="codes">编号数组</param>
        /// <returns>影响行数</returns>
        public int BatchSetCode(string[] ids, string[] codes)
        {
            int returnValue = 0;
            for (int i = 0; i < ids.Length; i++)
            {
                returnValue += this.SetProperty(ids[i], BaseBusinessLogic.FieldCode, codes[i]);
            }
            return returnValue;
        }

        #endregion public int BatchSetCode(string[] ids, string[] codes) 重置编号

        #region public virtual int ResetSortCode() 重新设置表的排序码

        /// <summary>
        /// 重新设置表的排序码
        /// </summary>
        /// <returns>影响行数</returns>
        public virtual int ResetSortCode()
        {
            int returnValue = 0;
            DataTable dataTable = this.GetDT(BaseBusinessLogic.FieldSortCode);
            BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper);
            string[] sortCode = sequenceManager.GetBatchSequence(this.CurrentTableName, dataTable.Rows.Count);
            int i = 0;
            foreach (DataRow dataRow in dataTable.Rows)
            {
                returnValue += this.SetProperty(dataRow[BaseBusinessLogic.FieldId].ToString(), BaseBusinessLogic.FieldSortCode, sortCode[i]);
                i++;
            }
            return returnValue;
        }

        #endregion public virtual int ResetSortCode() 重新设置表的排序码

        //
        // 获取一些属性
        //

        #region public string GetParentId(string id) 获取父级主键

        /// <summary>
        /// 获取父节点主键
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>父级主键</returns>
        public string GetParentId(string id)
        {
            return this.GetProperty(BaseBusinessLogic.FieldId, id, BaseBusinessLogic.FieldParentId);
        }

        #endregion public string GetParentId(string id) 获取父级主键

        #region public string GetParentIdByCode(string code) 获取父节点主键

        /// <summary>
        /// 获取父节点主键
        /// </summary>
        /// <param name="code">编号</param>
        /// <returns>父级主键</returns>
        public string GetParentIdByCode(string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldParentId);
        }

        #endregion public string GetParentIdByCode(string code) 获取父节点主键

        #region public string GetParentIdByCategory(string categoryId, string code) 获取父节点主键

        /// <summary>
        /// 获取父节点主键
        /// </summary>
        /// <param name="categoryId">分类主键</param>
        /// <param name="code">主键</param>
        /// <returns>父级主键</returns>
        public string GetParentIdByCategory(string categoryId, string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCategoryId, categoryId, BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldParentId);
        }

        #endregion public string GetParentIdByCategory(string categoryId, string code) 获取父节点主键

        #region public string GetFullName(string id) 获取名称

        /// <summary>
        /// 获取名称
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>名称</returns>
        public string GetFullName(string id)
        {
            return this.GetProperty(BaseBusinessLogic.FieldId, id, BaseBusinessLogic.FieldFullName);
        }

        #endregion public string GetFullName(string id) 获取名称

        #region public string GetFullNameByCategory(string code) 获取名称

        /// <summary>
        /// 获取名称
        /// </summary>
        /// <param name="code">编码</param>
        /// <returns>名称</returns>
        public string GetFullNameByCode(string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldFullName);
        }

        #endregion public string GetFullNameByCategory(string code) 获取名称

        #region public string GetFullNameByCategory(string categoryId, string code) 获取名称

        /// <summary>
        /// 获取名称
        /// </summary>
        /// <param name="categoryId">类别主键</param>
        /// <param name="code">编码</param>
        /// <returns>名称</returns>
        public string GetFullNameByCategory(string categoryId, string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCategoryId, categoryId, BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldFullName);
        }

        #endregion public string GetFullNameByCategory(string categoryId, string code) 获取名称

        #region public string GetCode(string id) 获取编码

        /// <summary>
        /// 获取编码
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>编号</returns>
        public string GetCode(string id)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldId, id, BaseBusinessLogic.FieldCode);
        }

        #endregion public string GetCode(string id) 获取编码

        #region public string GetId(string code) 获取主键

        /// <summary>
        /// 获取主键
        /// </summary>
        /// <param name="code">编号</param>
        /// <returns>主键</returns>
        public string GetId(string code)
        {
            return DbLogic.GetProperty(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldId);
        }

        #endregion public string GetId(string code) 获取主键

        //
        // 获取一些列表的常用方法
        //

        #region public DataTable GetDTByCategory(string categoryId) 获取列表

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="categoryId">类别主键</param>
        /// <returns>数据表</returns>
        public DataTable GetDTByCategory(string categoryId)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldCategoryId, categoryId, BaseBusinessLogic.FieldSortCode);
        }

        #endregion public DataTable GetDTByCategory(string categoryId) 获取列表

        #region public DataTable GetDTByParent(string parentId) 按父亲节点获取数据

        /// <summary>
        /// 按父亲节点获取数据
        /// </summary>
        /// <param name="parentId">父节点主键</param>
        /// <returns>数据表</returns>
        public DataTable GetDTByParent(string parentId)
        {
            return DbLogic.GetDT(DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldParentId, parentId, BaseBusinessLogic.FieldSortCode);
        }

        #endregion public DataTable GetDTByParent(string parentId) 按父亲节点获取数据

        //
        // 树型结构的算法
        //

        #region public DataTable GetParentsByCode(string fieldCode, string code, string order) 获取父节点列表

        /// <summary>
        /// 获取父节点列表
        /// </summary>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public DataTable GetParentsByCode(string fieldCode, string code, string order)
        {
            return DbLogic.GetParentsByCode(DbHelper, this.CurrentTableName, fieldCode, code, order);
        }

        #endregion public DataTable GetParentsByCode(string fieldCode, string code, string order) 获取父节点列表

        #region public DataTable GetChildrens(string fieldId, string id, string fieldParentId, string order) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="fieldId">主键字段</param>
        /// <param name="id">值</param>
        /// <param name="fieldParentId">父亲节点字段</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public DataTable GetChildrens(string fieldId, string id, string fieldParentId, string order)
        {
            return DbLogic.GetChildrens(DbHelper, this.CurrentTableName, fieldId, id, fieldParentId, order);
        }

        #endregion public DataTable GetChildrens(string fieldId, string id, string fieldParentId, string order) 获取子节点列表

        #region public DataTable GetChildrensByCode(string fieldCode, string code, string order) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public DataTable GetChildrensByCode(string fieldCode, string code, string order)
        {
            return DbLogic.GetChildrensByCode(DbHelper, this.CurrentTableName, fieldCode, code, order);
        }

        #endregion public DataTable GetChildrensByCode(string fieldCode, string code, string order) 获取子节点列表

        #region public DataTable GetParentChildrensByCode(string fieldCode, string code, string order) 获取父子节点列表

        /// <summary>
        /// 获取父子节点列表
        /// </summary>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public DataTable GetParentChildrensByCode(string fieldCode, string code, string order)
        {
            return DbLogic.GetParentChildrensByCode(DbHelper, this.CurrentTableName, fieldCode, code, order);
        }

        #endregion public DataTable GetParentChildrensByCode(string fieldCode, string code, string order) 获取父子节点列表

        #region public string[] GetParentsIDByCode(string fieldCode, string code) 获取父节点列表

        /// <summary>
        /// 获取父节点列表
        /// </summary>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <returns>主键数组</returns>
        public string[] GetParentsIDByCode(string fieldCode, string code)
        {
            return DbLogic.GetParentsIDByCode(DbHelper, this.CurrentTableName, fieldCode, code, string.Empty);
        }

        #endregion public string[] GetParentsIDByCode(string fieldCode, string code) 获取父节点列表

        #region public string[] GetChildrensId(string fieldId, string id, string fieldParentId) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="fieldId">主键字段</param>
        /// <param name="id">值</param>
        /// <param name="fieldParentId">父亲节点字段</param>
        /// <param name="order">排序</param>
        /// <returns>主键数组</returns>
        public string[] GetChildrensId(string fieldId, string id, string fieldParentId)
        {
            return DbLogic.GetChildrensId(DbHelper, this.CurrentTableName, fieldId, id, fieldParentId, string.Empty);
        }

        #endregion public string[] GetChildrensId(string fieldId, string id, string fieldParentId) 获取子节点列表

        #region public string[] GetChildrensByIDCode(string fieldCode, string code) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <returns>主键数组</returns>
        public string[] GetChildrensIdByCode(string fieldCode, string code)
        {
            return DbLogic.GetChildrensIdByCode(DbHelper, this.CurrentTableName, fieldCode, code, string.Empty);
        }

        #endregion public string[] GetChildrensByIDCode(string fieldCode, string code) 获取子节点列表

        #region public string[] GetParentChildrensIdByCode(string fieldCode, string code) 获取父子节点列表

        /// <summary>
        /// 获取父子节点列表
        /// </summary>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <returns>主键数组</returns>
        public string[] GetParentChildrensIdByCode(string fieldCode, string code)
        {
            return DbLogic.GetParentChildrensIdByCode(DbHelper, this.CurrentTableName, fieldCode, code, string.Empty);
        }

        #endregion public string[] GetParentChildrensIdByCode(string fieldCode, string code) 获取父子节点列表

        #region public string GetParentIdByCode(string fieldCode, string code) 获取父节点

        /// <summary>
        /// 获取父节点
        /// </summary>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编号</param>
        /// <returns>主键</returns>
        public string GetParentIdByCode(string fieldCode, string code)
        {
            return DbLogic.GetParentIdByCode(DbHelper, this.CurrentTableName, fieldCode, code);
        }

        #endregion public string GetParentIdByCode(string fieldCode, string code) 获取父节点

        //
        // 记录导航功能
        //

        public string PreviousID = string.Empty; // 上一个记录主键。
        public string NextID = string.Empty; // 下一个记录主键。

        #region public DataTable GetPreviousNextID(bool deletionStateCode, string id) 获得主键列表

        /// <summary>
        /// 获得主键列表中的，上一条，小一条记录的主键
        /// </summary>
        /// <param name="deletionStateCode">删除标志</param>
        /// <param name="id">备忘录ID</param>
        /// <returns>数据表</returns>
        public DataTable GetPreviousNextID(bool deletionStateCode, string id, string order)
        {
            string sqlQuery = " SELECT Id "
                            + " FROM " + this.CurrentTableName
                            + " WHERE (" + BaseBusinessLogic.FieldCreateUserId + " = " + DbHelper.GetParameter(BaseBusinessLogic.FieldCreateUserId)
                            + " AND " + BaseBusinessLogic.FieldDeletionStateCode + " = " + (deletionStateCode ? 1 : 0) + ")"
                            + " ORDER BY " + order;
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = BaseBusinessLogic.FieldCreateUserId;
            values[0] = UserInfo.Id;
            DataTable dataTable = new DataTable(this.CurrentTableName);
            DbHelper.Fill(dataTable, sqlQuery, DbHelper.MakeParameters(names, values));
            this.NextID = this.GetNextID(dataTable, id);
            this.PreviousID = this.GetPreviousID(dataTable, id);
            return dataTable;
        }

        #endregion public DataTable GetPreviousNextID(bool deletionStateCode, string id) 获得主键列表

        #region public void GetPreviousNextID(DataTable dataTable, string id) 获得主键列表

        /// <summary>
        /// 获取下一条、下一条记录主键
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <param name="id">当前记录主键</param>
        public void GetPreviousNextID(DataTable dataTable, string id)
        {
            this.PreviousID = this.GetPreviousID(dataTable, id);
            this.NextID = this.GetNextID(dataTable, id);
        }

        #endregion public void GetPreviousNextID(DataTable dataTable, string id) 获得主键列表

        #region private string GetPreviousID(string id) 获取上一条记录主键

        /// <summary>
        /// 获取上一条记录主键
        /// </summary>
        /// <param name="id">当前记录主键</param>
        /// <returns>上一条记录主键</returns>
        private string GetPreviousID(string id)
        {
            string returnValue = string.Empty;
            string sqlQuery = " SELECT TOP 1 " + BaseBusinessLogic.FieldId
                            + " FROM " + this.CurrentTableName
                            + " WHERE " + BaseBusinessLogic.FieldCreateOn + " = (SELECT MAX(" + BaseBusinessLogic.FieldCreateOn + ")"
                            + " FROM " + this.CurrentTableName
                            + " WHERE (" + BaseBusinessLogic.FieldCreateOn + "< (SELECT " + BaseBusinessLogic.FieldCreateOn
                            + " FROM " + this.CurrentTableName
                            + " WHERE " + BaseBusinessLogic.FieldId + " = " + DbHelper.GetParameter(BaseBusinessLogic.FieldId) + "))";
            sqlQuery += " AND (" + BaseBusinessLogic.FieldCreateUserId + " = " + DbHelper.GetParameter(BaseBusinessLogic.FieldCreateUserId) + " ) AND ( " + BaseBusinessLogic.FieldDeletionStateCode + " = 0 )) ";
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = BaseBusinessLogic.FieldId;
            values[0] = id;
            names[1] = BaseBusinessLogic.FieldCreateUserId;
            values[1] = UserInfo.Id;
            object returnObject = DbHelper.ExecuteScalar(sqlQuery, DbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                returnValue = returnObject.ToString();
            }
            return returnValue;
        }

        #endregion private string GetPreviousID(string id) 获取上一条记录主键

        #region public string GetPreviousID(DataTable dataTable, string id) 获取下一条备忘录ID

        /// <summary>
        /// 获取上一条记录主键
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <param name="id">当前记录主键</param>
        /// <returns>上一条记录主键</returns>
        public string GetPreviousID(DataTable dataTable, string id)
        {
            string returnValue = string.Empty;
            foreach (DataRowView dataRowView in dataTable.DefaultView)
            {
                if (dataRowView[BaseBusinessLogic.FieldId].ToString().Equals(id))
                {
                    break;
                }
                returnValue = dataRowView[BaseBusinessLogic.FieldId].ToString();
            }

            return returnValue;
        }

        #endregion public string GetPreviousID(DataTable dataTable, string id) 获取下一条备忘录ID

        #region private string GetNextID(string id) 获取下一条记录主键

        /// <summary>
        /// 获取下一条记录主键
        /// </summary>
        /// <param name="id">当前记录主键</param>
        /// <returns>下一条记录主键</returns>
        private string GetNextID(string id)
        {
            string returnValue = string.Empty;
            string sqlQuery = " SELECT TOP 1 " + BaseBusinessLogic.FieldId
                            + " FROM " + this.CurrentTableName
                            + " WHERE " + BaseBusinessLogic.FieldCreateOn + " = (SELECT MIN(" + BaseBusinessLogic.FieldCreateOn + ")"
                            + " FROM " + this.CurrentTableName
                            + " WHERE (" + BaseBusinessLogic.FieldCreateOn + "> (SELECT " + BaseBusinessLogic.FieldCreateOn
                            + " FROM " + this.CurrentTableName
                            + " WHERE " + BaseBusinessLogic.FieldId + " = " + DbHelper.GetParameter(BaseBusinessLogic.FieldId) + "))";
            sqlQuery += " AND (" + BaseBusinessLogic.FieldCreateUserId + " = " + DbHelper.GetParameter(BaseBusinessLogic.FieldCreateUserId) + ") AND ( " + BaseBusinessLogic.FieldDeletionStateCode + " = 0 )) ";
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = BaseBusinessLogic.FieldId;
            values[0] = id;
            names[1] = BaseBusinessLogic.FieldCreateUserId;
            values[1] = UserInfo.Id;
            object returnObject = DbHelper.ExecuteScalar(sqlQuery, DbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                returnValue = returnObject.ToString();
            }
            return returnValue;
        }

        #endregion private string GetNextID(string id) 获取下一条记录主键

        #region public string GetNextID(DataTable dataTable, string id) 获取下一条记录主键

        /// <summary>
        /// 获取下一条记录主键
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <param name="id">当前记录主键</param>
        /// <returns>下一条记录主键</returns>
        public string GetNextID(DataTable dataTable, string id)
        {
            string returnValue = string.Empty;
            bool finded = false;
            foreach (DataRowView dataRowView in dataTable.DefaultView)
            {
                if (finded)
                {
                    returnValue = dataRowView[BaseBusinessLogic.FieldId].ToString();
                    break;
                }
                if (dataRowView[BaseBusinessLogic.FieldId].ToString().Equals(id))
                {
                    finded = true;
                }
            }
            return returnValue;
        }

        #endregion public string GetNextID(DataTable dataTable, string id) 获取下一条记录主键

        //
        // 状态码的获取
        //

        private string returnStatusCode = StatusCode.Error.ToString();

        /// <summary>
        /// 运行状态返回值
        /// </summary>
        public string ReturnStatusCode
        {
            get
            {
                return this.returnStatusCode;
            }
            set
            {
                this.returnStatusCode = value;
            }
        }

        private string returnStatusMessage = string.Empty;

        /// <summary>
        /// 运行状态的信息
        /// </summary>
        public string ReturnStatusMessage
        {
            get
            {
                return this.returnStatusMessage;
            }
            set
            {
                this.returnStatusMessage = value;
            }
        }

        public string GetStateMessage(string statusCode)
        {
            if (String.IsNullOrEmpty(statusCode))
            {
                return string.Empty;
            }
            StatusCode status = (StatusCode)Enum.Parse(typeof(StatusCode), statusCode, true);
            return this.GetStateMessage(status);
        }

        #region public string GetStateMessage(StatusCode statusCode) 获得状态的信息

        /// <summary>
        /// 获得状态的信息
        /// </summary>
        /// <param name="statusCode">程序运行状态</param>
        /// <returns>返回信息</returns>
        public string GetStateMessage(StatusCode statusCode)
        {
            string returnValue = string.Empty;
            switch (statusCode)
            {
                case StatusCode.Error:
                    returnValue = AppMessage.MSG0001;
                    break;

                case StatusCode.OK:
                    returnValue = AppMessage.MSG9965;
                    break;

                case StatusCode.UserNotFound:
                    returnValue = AppMessage.MSG9966;
                    break;

                case StatusCode.PasswordError:
                    returnValue = AppMessage.MSG9967;
                    break;

                case StatusCode.LogOnDeny:
                    returnValue = AppMessage.MSG9968;
                    break;

                case StatusCode.ErrorOnLine:
                    returnValue = AppMessage.MSG0048;
                    break;

                case StatusCode.ErrorMacAddress:
                    returnValue = AppMessage.MSG0049;
                    break;

                case StatusCode.ErrorIPAddress:
                    returnValue = AppMessage.MSG0050;
                    break;

                case StatusCode.ErrorOnLineLimit:
                    returnValue = AppMessage.MSG0051;
                    break;

                case StatusCode.PasswordCanNotBeNull:
                    returnValue = AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9961);
                    break;

                case StatusCode.ErrorDeleted:
                    returnValue = AppMessage.MSG0005;
                    break;

                case StatusCode.SetPasswordOK:
                    returnValue = AppMessage.Format(AppMessage.MSG9963, AppMessage.MSG9964);
                    break;

                case StatusCode.OldPasswordError:
                    returnValue = AppMessage.Format(AppMessage.MSG0040, AppMessage.MSG9961);
                    break;

                case StatusCode.ChangePasswordOK:
                    returnValue = AppMessage.Format(AppMessage.MSG9962, AppMessage.MSG9964);
                    break;

                case StatusCode.OKAdd:
                    returnValue = AppMessage.MSG0009;
                    break;

                case StatusCode.CanNotLock:
                    returnValue = AppMessage.MSG0043;
                    break;

                case StatusCode.LockOK:
                    returnValue = AppMessage.MSG0044;
                    break;

                case StatusCode.OKUpdate:
                    returnValue = AppMessage.MSG0010;
                    break;

                case StatusCode.OKDelete:
                    returnValue = AppMessage.MSG0013;
                    break;

                case StatusCode.ErrorCodeExist:

                    // "编号已存在,不可以重复."
                    returnValue = AppMessage.Format(AppMessage.MSG0008, AppMessage.MSG9977);
                    break;

                case StatusCode.ErrorNameExist:

                    // "名称已存在,不可以重复."
                    returnValue = AppMessage.Format(AppMessage.MSG0008, AppMessage.MSG9978);
                    break;

                case StatusCode.ErrorValueExist:

                    // "值已存在,不可以重复."
                    returnValue = AppMessage.Format(AppMessage.MSG0008, AppMessage.MSG9800);
                    break;

                case StatusCode.ErrorUserExist:

                    // "用户名已存在,不可以重复."
                    returnValue = AppMessage.Format(AppMessage.MSG0008, AppMessage.MSG9957);
                    break;

                case StatusCode.ErrorDataRelated:
                    returnValue = AppMessage.MSG0033;
                    break;

                case StatusCode.ErrorChanged:
                    returnValue = AppMessage.MSG0006;
                    break;

                case StatusCode.UserNotEmail:
                    returnValue = AppMessage.MSG9910;
                    break;

                case StatusCode.UserLocked:
                    returnValue = AppMessage.MSG9911;
                    break;

                case StatusCode.UserNotActive:
                    returnValue = AppMessage.MSG9912;
                    break;

                case StatusCode.UserIsActivate:
                    returnValue = AppMessage.MSG9913;
                    break;

                case StatusCode.NotFound:
                    returnValue = AppMessage.MSG9956;
                    break;

                //// 开始审核
                //case AuditStatus.StartAudit:
                //    returnValue = AppMessage.MSG0009;
                //    break;
                //// 审核通过
                //case AuditStatus.AuditPass:
                //    returnValue = AppMessage.MSG0009;
                //    break;
                //// 待审核
                //case AuditStatus.WaitForAudit:
                //    returnValue = AppMessage.MSG0010;
                //    break;
                //// 审核驳回
                //case AuditStatus.AuditReject:
                //    returnValue = AppMessage.MSG0009;
                //    break;
                //// 审核结束
                //case AuditStatus.AuditComplete:
                //    returnValue = AppMessage.MSG0010;
                //    break;
                //// 递交成功。
                //case AuditStatus.SubmitOK:
                //    returnValue = AppMessage.MSG0009;
                //    break;
            }
            return returnValue;
        }

        #endregion public string GetStateMessage(StatusCode statusCode) 获得状态的信息

        public virtual int SetTableColumns(string tableCode, string tableName, string columnCode, string columnName)
        {
            BaseSequenceManager sequenceManager = new BaseSequenceManager(this.DbHelper);
            string sortCode = sequenceManager.GetSequence(BaseTableColumnsTable.TableName);

            // 插入数据
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
            sqlBuilder.BeginInsert(BaseTableColumnsTable.TableName);

            sqlBuilder.SetValue(BaseTableColumnsTable.FieldTableCode, tableCode);
            sqlBuilder.SetValue(BaseTableColumnsTable.FieldTableName, tableName);
            sqlBuilder.SetValue(BaseTableColumnsTable.FieldColumnCode, columnCode);
            sqlBuilder.SetValue(BaseTableColumnsTable.FieldColumnName, columnName);
            sqlBuilder.SetValue(BaseTableColumnsTable.FieldSortCode, sortCode);

            sqlBuilder.SetValue(BaseTableColumnsTable.FieldCreateUserId, UserInfo.Id);
            sqlBuilder.SetValue(BaseTableColumnsTable.FieldCreateBy, UserInfo.RealName);
            sqlBuilder.SetDBNow(BaseTableColumnsTable.FieldCreateOn);

            sqlBuilder.SetValue(BaseTableColumnsTable.FieldModifiedUserId, UserInfo.Id);
            sqlBuilder.SetValue(BaseTableColumnsTable.FieldModifiedBy, UserInfo.RealName);
            sqlBuilder.SetDBNow(BaseTableColumnsTable.FieldModifiedOn);
            return sqlBuilder.EndInsert();
        }
    }
}